package org.jeecg.modules.jd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.jd.entity.JD_order_sku;
import org.jeecg.modules.jd.entity.JD_position;
import org.jeecg.modules.jd.mapper.JD_order_skuMapper;
import org.jeecg.modules.jd.service.IJD_order_skuService;
import org.jeecg.modules.jd.service.IJD_positionService;
import org.jeecg.modules.jd.util.JDOrderUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 京东订单商品表
 * @Author: jeecg-boot
 * @Date:   2020-06-12
 * @Version: V1.0
 */
@Service
public class JD_order_skuServiceImpl extends ServiceImpl<JD_order_skuMapper, JD_order_sku> implements IJD_order_skuService {

    @Autowired
    @Lazy(true)
    private IJD_positionService jD_positionService;

    @Override
    public Result<?> pageJDOrders(String user_id, Page<JD_order_sku> page, JD_order_sku jd_order_sku) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", user_id);
        JD_position jd_position = jD_positionService.getOne(queryWrapper);
        if(null==jd_position){
            return Result.error("推广位不存在");
        }
        //QueryWrapper  orderQ=new QueryWrapper();
        jd_order_sku.setPositionId(jd_position.getId());
        //orderQ.eq("position_id",jd_position.getId());
        List<JD_order_sku>  jd_order_skuList=this.baseMapper.pageJDOrders(page, jd_order_sku);
        for (JD_order_sku jdOrderSku : jd_order_skuList) {

         String orderDetail=   JDOrderUtil.getOrdersDetail(String .valueOf( jdOrderSku.getSkuId()));
            jdOrderSku.setOrderDetails(orderDetail);

        }
        return Result.ok(page.setRecords(jd_order_skuList));
    }
}
